const { DataTypes } = require('sequelize');
const { sequelize } = require('../config/db');

const SharedImage = sequelize.define('SharedImage', {
  user_id: {
    type: DataTypes.INTEGER,
    allowNull: false,
    references: {
      model: 'Users',
      key: 'id'
    }
  },
  title: {
    type: DataTypes.STRING(255),
    allowNull: false,
    comment: '图片标题'
  },
  description: {
    type: DataTypes.TEXT,
    allowNull: true,
    comment: '图片介绍/描述'
  },
  category: {
    type: DataTypes.STRING(100),
    allowNull: false,
    comment: '图片类别'
  },
  image_path: {
    type: DataTypes.STRING(500),
    allowNull: false,
    comment: '图片存储路径'
  },
  thumbnail_path: {
    type: DataTypes.STRING(500),
    allowNull: true,
    comment: '缩略图路径'
  },
  original_prompt: {
    type: DataTypes.TEXT,
    allowNull: true,
    comment: '生成图片时使用的原始提示词'
  },
  ai_role_id: {
    type: DataTypes.INTEGER,
    allowNull: true,
    references: {
      model: 'AIRoles',
      key: 'id'
    }
  },
  tags: {
    type: DataTypes.JSON,
    allowNull: true,
    comment: '图片标签'
  },
  is_public: {
    type: DataTypes.BOOLEAN,
    defaultValue: true,
    comment: '是否公开显示'
  },
  view_count: {
    type: DataTypes.INTEGER,
    defaultValue: 0,
    comment: '浏览次数'
  },
  like_count: {
    type: DataTypes.INTEGER,
    defaultValue: 0,
    comment: '点赞次数'
  },
  file_size: {
    type: DataTypes.BIGINT,
    allowNull: true,
    comment: '文件大小'
  },
  image_width: {
    type: DataTypes.INTEGER,
    allowNull: true,
    comment: '图片宽度'
  },
  image_height: {
    type: DataTypes.INTEGER,
    allowNull: true,
    comment: '图片高度'
  },
  created_at: {
    type: DataTypes.DATE,
    defaultValue: DataTypes.NOW
  },
  updated_at: {
    type: DataTypes.DATE,
    defaultValue: DataTypes.NOW
  }
}, {
  timestamps: false,
  indexes: [
    { fields: ['category'] },
    { fields: ['user_id'] },
    { fields: ['created_at'] },
    { fields: ['is_public'] }
  ]
});

module.exports = SharedImage;